package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.WhStockOutDeliveryImg;
import com.dingreading.cloud.admin.entity.table.WhStockOutDeliveryImgTableDef;
import com.dingreading.cloud.admin.mapper.WhStockOutDeliveryImgMapper;
import com.dingreading.cloud.admin.service.WhStockOutDeliveryImgService;
import com.mybatisflex.core.query.QueryCondition;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 服务层实现。
 *
 * @author Administrator
 * @since 2024-07-08
 */
@Service
public class WhStockOutDeliveryImgServiceImpl extends BaseServiceImpl<WhStockOutDeliveryImgMapper, WhStockOutDeliveryImg, WhStockOutDeliveryImgTableDef> implements WhStockOutDeliveryImgService {

    @Override
    protected WhStockOutDeliveryImgTableDef getTable() {
        return WhStockOutDeliveryImgTableDef.whStockOutDeliveryImg;
    }


    @Override
    public List<WhStockOutDeliveryImg> listByDeliveryId(Long deliveryId) {
        return getMapper().selectListByCondition(table.deliveryId.eq(deliveryId));
    }

    @Override
    public List<WhStockOutDeliveryImg> listByDeliveryIdIn(List<Long> deliveryIdList) {
        return getMapper().selectListByCondition(table.deliveryId.in(deliveryIdList));
    }

    @Override
    public void deleteByImgIdNotIn(Long deliveryId, List<Long> updateIdList) {
        QueryCondition condition = table.deliveryId.eq(deliveryId);
        if (CollectionUtils.isNotEmpty(updateIdList))
            condition.and(table.id.notIn(updateIdList));
        getMapper().deleteByCondition(condition);
    }

    @Override
    public void deleteByDeliveryId(Long deliveryId) {
        getMapper().deleteByCondition(table.deliveryId.eq(deliveryId));
    }

    @Override
    public List<WhStockOutDeliveryImg> listByImgIdNotIn(Long deliveryId, List<Long> updateIdList) {
        QueryCondition condition = table.deliveryId.eq(deliveryId);
        if (CollectionUtils.isNotEmpty(updateIdList))
            condition.and(table.id.notIn(updateIdList));
        return getMapper().selectListByCondition(condition);
    }
}
